package com.niiwoo.civet.scheduler.trigger;

import java.util.concurrent.CompletableFuture;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Reference;
import com.niiwoo.civet.trade.service.intelligenceInvest.IntelligenceInvestDubboService;

import lombok.extern.slf4j.Slf4j;

/**
 * 智能投包流标
 * 
 * @author liuchun
 *
 *         2018年11月6日
 */
@Component
@Slf4j
public class IntelligenceInvestJobTrigger {
	@Reference(version = "1.0.0")
	private IntelligenceInvestDubboService intelligenceInvestDubboService;

	@Scheduled(cron = "${intelligence.invest}")
	public void intelligenceTriggerInvest() {
		long time = System.currentTimeMillis();
		log.info("定时触发智能投再次触发投资开始");
		try {
			intelligenceInvestDubboService.triggerInvest();
		} catch (Exception e) {
			log.info("定时触发智能投再次触发投资异常,异常{}",e.getMessage());
		}
		 
		
		log.info("定时触发智能投再次触发投资结束,耗时{}",System.currentTimeMillis()-time);
	}
	@Scheduled(cron = "${intelligence.cancel}")
	public void intelligenceTriggerCancel() {
		long time = System.currentTimeMillis();
		log.info("定时触发智能投再次触发取消投资开始");
		try {
			intelligenceInvestDubboService.triggerCancel();
		} catch (Exception e) {
			log.info("定时触发智能投再次触发取消投资异常,异常{}",e.getMessage());
		}
		 
		
		log.info("定时触发智能投再次触发取消投资结束,耗时{}",System.currentTimeMillis()-time);
	}

	@Scheduled(cron = "${intelligence.doPackage}")
	public void doPackageForJob() {
		log.info("定时打包...");
		CompletableFuture.runAsync(() -> intelligenceInvestDubboService.doPackageForJob());
	}

	@Scheduled(cron = "${intelligence.addProject}")
	public void addProjectForJob() {
		log.info("定时加标...");
		CompletableFuture.runAsync(() -> intelligenceInvestDubboService.addProjectForJob());
	}

	@Scheduled(cron = "${intelligence.doPublish}")
	public void doPublishForJob() {
		log.info("定时发布...");
		CompletableFuture.runAsync(() -> intelligenceInvestDubboService.doPublishForJob());
	}
}
